<template>
  <div class="__CONTAINER_H__">
    <div class="login_box">
      <form @submit.prevent="submit($event)">
        <h2>Login</h2>
        <div class="icon1">
          <input type="text" v-model="form.UserName" name="user" id="user" placeholder="UserName" />
        </div>
        <div class="icon1">
          <input
            type="password"
            v-model="form.Password"
            name="password"
            id="pas"
            placeholder="Password"
          />
        </div>
        <div class="bottom">
          <button type="submit" class="login_btn">login</button>
        </div>
        <p>
          <router-link to="#">忘记密码?</router-link>
        </p>

        <p class="text-danger">{{err}}</p>
        <Prompt ref="prompt"></Prompt>
      </form>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import Prompt from "../components/Prompt";

export default {
  name: "Login",
  data() {
    return {
      form: {
        UserName: "",
        Password: ""
      },
      err: ""
    };
  },
  components: {
    Prompt
  },
  methods: {
    submit: function(event) {
      event.preventDefault();

      axios
        .post("/api/user/Login", this.form)
        .then(res => {
          // window.console.log(res.data.token);
          sessionStorage.setItem("token", res.data.token); //保持token
          this.$refs.prompt.alertDia("登录成功", "manage");
        })
        .catch(err => {
          this.err = err.response.data.message;
          window.console.log(err.response.data);
        });
    }
  }
};
</script>

<style scoped>
.__CONTAINER_H__ {
  width: 100vw;
  height: 100vh;
  padding: 0;
  margin: auto;
  position: relative;
  background: url("~@/assets/1.jpg");
}

.login_box {
  width: 500px;
  height: 300px;
  margin: auto;
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  /* background-color: rgba(0, 0, 0, 0.5); */
}

form {
  width: 100%;
  height: 100%;
  text-align: center;
}

h2 {
  font-size: 1.6em;
  line-height: 1.6em;
  color: #ffffff;
  text-align: center;
  padding-bottom: 25px;
  text-transform: capitalize;
}
.icon1 {
  margin: 0 0 2em;
  border: 1px solid #525252;
  padding: 0.7em 0em;
  background: rgba(255, 255, 255, 0.22);
  border-radius: 26px;
}
input {
  outline: none;
  font-size: 15px;
  color: #fff;
  border: none;
  width: 90%;
  display: inline-block;
  background: transparent;
  font-family: "Muli", sans-serif;
  text-align: center;
  letter-spacing: 2px;
}
input::-webkit-input-placeholder {
  color: #fff;
}
.bottom {
  margin: 2em 0 0;
}
button {
  background: #3be8b0;
  color: #fff;
  font-size: 17px;
  text-transform: capitalize;
  padding: 0.5em 2em;
  letter-spacing: 1px;
  transition: 0.5s all;
  -webkit-transition: 0.5s all;
  -moz-transition: 0.5s all;
  -o-transition: 0.5s all;
  display: inline-block;
  cursor: pointer;
  outline: none;
  border: none;
  font-family: "Muli", sans-serif;
  width: 100%;
  border-radius: 25px;
}
button:hover {
  background: #af5e7b;
}
p {
  margin-top: 2em;
}
p > a {
  color: red;
}
</style>